package com.ruoyi.warehousemanager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.warehousemanager.domain.Item;
import com.ruoyi.warehousemanager.domain.NewApply;
import com.ruoyi.warehousemanager.domain.Operate;
import com.ruoyi.warehousemanager.pojo.ItemVO;
import com.ruoyi.warehousemanager.pojo.OperateVO;
import com.ruoyi.warehousemanager.service.IOperateService;
import com.ruoyi.warehousemanager.service.ItemService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warehousemanager.service.IOperateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 外库操作管理Controller
 *
 * @author xin
 * @date 2023-06-01
 */
@RestController
@RequestMapping("/warehousemanager/operate")
public class OperateController extends BaseController
{
    @Autowired
    private IOperateService OperateService;

    @Autowired
    private ItemService itemService;


    /**
     * 查询外库操作管理列表
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:operate:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody OperateVO operate)
    {
        startPage();
        List<OperateVO> list = OperateService.selectOperateList(operate);
        return getDataTable(list);
    }

    /**
     * 导出外库列表
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:operate:export')")
    @Log(title = "外库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OperateVO operate) {
        List<OperateVO> list = OperateService.selectOperateList(operate);
        ExcelUtil<OperateVO> util = new ExcelUtil<OperateVO>(OperateVO.class);
        util.exportExcel(response, list, "外库管理数据");
    }

    /**
     * 获取外库操作管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:operate:query')")
    @GetMapping(value = "/{operateId}")
    public AjaxResult getInfo(@PathVariable("operateId") Long operateId)
    {
        return success(OperateService.selectOperateByOperateId(operateId));
    }

    /**
     * 新增外库操作管理
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:operate:add')")
    @Log(title = "外库操作管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Operate operate)
    {

        return toAjax(OperateService.insertOperate(operate));
    }

    /**
     * 修改外库操作管理
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:operate:edit')")
    @Log(title = "外库操作管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Operate operate)
    {

        return toAjax(OperateService.updateOperate(operate));
    }

    /**
     * 删除外库操作管理
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:operate:remove')")
    @Log(title = "外库操作管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{operateIds}")
    public AjaxResult remove(@PathVariable Long[] operateIds)
    {
        return toAjax(OperateService.deleteOperateByOperateIds(operateIds));
    }
}
